-- TB_<TableName>
CREATE TABLE <PREFIX><TableName> AS SELECT 'LOG_MG' LOG_MG, SYSTIMESTAMP 'TIME_REC', TBS.* FROM <TableName> TBS WHERE 1=0;
ALTER TABLE <PREFIX><TableName>  MODIFY (LOG_MG varchar2(255));

create or replace TRIGGER <PREFIX><TableName>_TRG
	AFTER DELETE OR INSERT OR UPDATE
	ON <TableName>
	FOR EACH ROW
DECLARE
	LOG_MG varchar2(255) := '';
--PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN	
	IF INSERTING  THEN
		LOG_MG := 'INSERTING - ';
		-- insert new
		INSERT INTO <PREFIX><TableName>(LOG_MG, TIME_REC<INS_COLUMNS_NAME>)
			values(LOG_MG  || 'NEW', SYSTIMESTAMP<INS_NEW>);
	ELSIF UPDATING THEN
		LOG_MG := 'UPDATING - ';
		-- insert old
		INSERT INTO <PREFIX><TableName>(LOG_MG, TIME_REC<INS_COLUMNS_NAME>)
			values(LOG_MG  || 'OLD', SYSTIMESTAMP<INS_OLD>);
		-- insert new
		INSERT INTO <PREFIX><TableName>(LOG_MG, TIME_REC<INS_COLUMNS_NAME>)
			values(LOG_MG  || 'NEW', SYSTIMESTAMP<INS_NEW>);
	ELSIF DELETING THEN
		LOG_MG := 'DELETING - ';
		-- insert old
		INSERT INTO <PREFIX><TableName>(LOG_MG, TIME_REC<INS_COLUMNS_NAME>)
			values(LOG_MG  || 'OLD', SYSTIMESTAMP<INS_OLD>);
	END IF;
END;
/
ALTER TRIGGER <PREFIX><TableName>_TRG ENABLE;
-- Next
